package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BedServiceImpl implements BedService {
////
    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public int addBed(BedDto bedDto) {
        // TODD 是否需要做重命名判断还是依赖数据库抛出异常
        // dto ==> entity
        Bed bed = BeanUtil.copyProperties(bedDto, Bed.class);
        bed.setBedStatus(0); // 默认床位状态为0(未入住)
        return bedMapper.insert(bed);
    }

    @Override
    public int deleteById(Long id) {
        // 该床位在使用不能删除:在后端做判断,还是依赖前端的封禁
        return bedMapper.deleteById(id);
    }

    @Override
    public int updateBed(BedDto bedDto) {
        Bed bed = BeanUtil.copyProperties(bedDto, Bed.class);
        return bedMapper.updateBed(bed);
    }

    @Override
    public Bed readBedById(Long id) {
        return bedMapper.readBedById(id);
    }


}

